<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {	
	public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
			'authError' => 'Bạn không có quyền xem trang này',			
        )
    );
	public $helpers = array('Html','Form','Session');
	
	function beforeFilter () {
		if($current_user = $this->Auth->user()){
			$this->set(compact('current_user'));
		}
        $this->Auth->autoRedirect = false;
    }
	
	function construct()
	{
		parent::construct();
		$path = func_get_args();

		$count = count($path);
		if (!$count) {
			$this->redirect('/');
		}
		$title_for_layout = null;

		if (!empty($path[$count - 1])) {
			$title_for_layout = Inflector::humanize($path[$count - 1]);
		}
		$this->set(compact('title_for_layout'));
		$this->render(implode('/', $path));
	}
}